package com.fram.controller.api.android;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fram.bean.admin.android.category.request.CategoryAndroidRequest;
import com.fram.bean.sys.ResponseMsg;
import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProException;
import com.fram.common.util.PublicMethod;
import com.fram.common.util.apiversion.ApiVersion;
import com.fram.common.util.base.BaseController;
import com.fram.entity.DistributorProjectCategory;
import com.fram.service.api.v1.android.GoodsCategoryAndroidService;

@RestController
@RequestMapping("/api/{version}/app/manage/goods/category")
public class GoodsCategoryAndroidController extends BaseController{
	
	private static Logger LOG = LoggerFactory.getLogger(GoodsCategoryAndroidController.class);
	
	@Autowired
	private GoodsCategoryAndroidService goodsCategoryAndroidService;
	
	//增加 店铺 分类
	@ApiVersion(1.0)
	@RequestMapping("add")
	private ResponseMsg add(@RequestBody DistributorProjectCategory request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			request.setDistributorId(getDistributorId());
			goodsCategoryAndroidService.add(request);
		} catch (ProException e) {
			LOG.error("-增加分类错误-->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--增加分类异常--->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	//展示 店铺 分类
	@ApiVersion(1.0)
	@RequestMapping("list")
	private ResponseMsg list(@RequestBody CategoryAndroidRequest request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			request.setDistributorId(getDistributorId());
			msg.setData(goodsCategoryAndroidService.listForAndroid(request));
		} catch (ProException e) {
			LOG.error("-分类展示错误-->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--分类展示异常--->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	
	//添加商品 用到
	@ApiVersion(1.0)
	@RequestMapping("listWithChildren")
	private ResponseMsg listWithChildren() {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			msg.setData(goodsCategoryAndroidService.listWithChildren(getDistributorId()));
		} catch (ProException e) {
			LOG.error("-添加商品中的-分类展示错误-->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("--添加商品中的-分类展示异常--->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	
}
